from flask import Flask
from flask import render_template
import pymysql
from flask import request

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/search')
def search():
    kw = request.args.get('kw')  # 获取用户get请求的参数和值
    count = request.args.get('count')
    cursor.execute("select*from image where `name` like `%{}%`".format(kw))
    data = cursor.fetchmany(int(count))
    return render_template('imdex.html', image=data)


if __name__ == '__main__':
    coon = pymysql.connect(host='localhost',
                           port=3306,
                           user='root',
                           passwd='jingfei',
                           db='表格',
                           charset='UTF8',
                           cursorclass=pymysql.cursors.DictCursor,

                           )
    cursor = coon.cursor()
    app.run(debug=True)
